package com.wen.controller;

import cn.hutool.db.Page;
import com.github.pagehelper.PageInfo;
import com.wen.pojo.Purchase;
import com.wen.pojo.Store;
import com.wen.service.ProductService;
import com.wen.service.PurchaseService;
import com.wen.service.StoreService;
import com.wen.utils.PageBean;
import com.wen.utils.Result;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/purchase")
public class PurchaseController {
    @Autowired
    private PurchaseService purchaseService;

    //添加采购单
    @RequestMapping("/purchase-add")
    public Result addPurchase(@RequestBody Purchase purchase){
        return purchaseService.addCh(purchase);
    }

    //分页查询采购单
    @RequestMapping("/purchase-page-list")
    public Result<PageBean<Purchase>> allPurchaseList(Integer pageNum , Integer pageSize, Purchase purchase){
        PageBean<Purchase> list = purchaseService.allPurchaseList(pageNum, pageSize, purchase);
        return Result.ok(200,"查询成功",list);
    }
    //查询仓库
    @Autowired
    private ProductService productService;
    @RequestMapping("/store-list")
    public Result storeList(){
        List<Store> storeList = productService.findStoreList();
        return Result.ok(200,"查询成功",storeList);
    }
    //删除采购单
    @RequestMapping("/purchase-delete/{buyId}")
    public Result delBuyList(@PathVariable Integer buyId){
        return purchaseService.delBuyList(buyId);
    }
    //修改采购单
    @RequestMapping("/purchase-update")
    public Result updBuyList(@RequestBody Purchase purchase){
        return purchaseService.updBuyList(purchase);
    }

    //生成入库单
    @RequestMapping("/in-warehouse-record-add")
    public Result addInWare(@RequestBody Purchase purchase){
        return purchaseService.addInWare(purchase);
    }
}
